package com.qing.gui.jframe;

import javax.swing.*;
import java.awt.*;

/**
 * 给标签设置图标
 */
public class IconDemo extends JFrame implements Icon {
    private int width;
    private int height;

    public IconDemo() {
    }

    public IconDemo(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public void init() {
        IconDemo iconDemo = new IconDemo(20, 20);
        JLabel label = new JLabel("图标初学", iconDemo, SwingConstants.CENTER);
        Container contentPane = this.getContentPane();
        contentPane.setBackground(Color.PINK);
        contentPane.add(label);
        this.setVisible(true);
        this.setBounds(500, 400, 500, 500);
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        //画一个实心的圆
        g.fillOval(x, y, width, height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }


    public static void main(String[] args) {
        new IconDemo().init();
    }

}
